<template>
  <div id="main-content">
    <div class="content">
      <el-page-header @back="goBackToList" title="返回列表" content="预售许可证信息">
      </el-page-header>
      <div class="toolBar">
         <el-link class="info_link" type="primary"  @click="hrefTo('hourseBaseInfo')" icon="el-icon-s-home">基本信息</el-link>
         <el-link class="info_link" type="primary"  @click="hrefTo('hourseEstateInfo')" icon="el-icon-house" >小区信息</el-link>
         <el-link class="info_link" type="primary" @click="hrefTo('hourseImage')" icon="el-icon-picture">图片管理</el-link>
         <el-link class="info_link" type="primary" @click="hrefTo('hourseOpeningInfo')" icon="el-icon-star-on" >开盘信息</el-link>
         <el-link class="info_link" type="primary"  icon="el-icon-platform-eleme" disabled><h3>预售许可证信息</h3></el-link>
         <el-link class="info_link" type="primary" @click="hrefTo('hourseSaleInfo')" icon="el-icon-s-shop">销售信息</el-link>
         <el-link class="info_link" type="primary" href="" icon="el-icon-s-promotion">相关房产</el-link>
        <el-button type="primary" @click="saveHoursePresaleInfo()" :loading="submitLoading">保存</el-button>
      </div>
      <el-form ref="form"  label-width="150px" >
        <el-button type="success" icon="el-icon-plus"  @click="addOne">增加</el-button>
        <div v-for="(presale,index) in presales" :key="'presale-'+index" class="presale-content">
            <el-button type="danger" icon="el-icon-delete" size="mini" circle  @click="removeOne(index)" title="删除"></el-button>
            <el-form-item label="预售许可证号">
              <el-input v-model="presale.presalePermit" width="200"></el-input>
            </el-form-item>
            <el-form-item label="发证时间">
              <el-date-picker
                v-model="presale.permitDate"
                type="date"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="关联(绑定)楼栋">
              <el-input v-model="presale.relationBuilding"></el-input>
            </el-form-item>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      hourseId:"",
      submitLoading:false,
      presales:[]
    };
  },
  methods:{
    saveHoursePresaleInfo(){
      this.submitLoading = true;
      for(var i=0;i<this.presales.length;i++){
        this.presales[i].hourseId = this.hourseId;
      }
      this.$http.post("/api/hoursePresaleInfo/save/"+this.hourseId,this.presales).then(()=>{
          this.$notify({
            title: '提示',
            message: '保存成功',
            type: 'success'
          });
          this.getHoursePresaleInfo(this.hourseId)
          this.submitLoading = false;
      });
    },
    getHoursePresaleInfo(hourseId){
      this.$http
        .get("/api/hoursePresaleInfo/get/" + hourseId)
        .then(response => {
          if (response && response.data) {
            this.presales = response.data;
          }
        });
    },
    hrefTo(moduleName){
      this.$router.push("/"+moduleName+"/"+this.hourseId)
    },
    addOne(){
      this.presales.push({
        id:"",
        presalePermit:"",
        permitDate:"",
        relationBuilding:""
      });
    },
    removeOne(index){
      // if(this.presales.length == 1){
      //   return;
      // }
      this.presales.splice(index,1);
    },
    goBackToList(){
      this.$router.push("/hourseList");
    }
  },
  created() {
    this.hourseId = this.$route.params.hourseId;
    this.getHoursePresaleInfo(this.hourseId);
  }
};
</script>
<style scoped>
.presale-content{
  border: 2px solid #ebebeb;
  margin-top: 10px;
  padding: 10px;
}
</style>